﻿Imports System.Threading

Public Class FormBase

#Region "variables"
    Private m_Timer As Threading.Timer = Nothing
    Protected m_Game As IGame = Nothing
#End Region

    Private Sub ProcessRunningCallback(ByVal state As Object)

        If Me.m_Game.IsRunning Then
            Me.setText(Me.tsslbInfo, "程序已经运行")
        Else
            Me.m_Game.Init()
            Me.setText(Me.tsslbInfo, "程序未运行")
        End If
    End Sub

    Private Sub setText(ByVal control As ToolStripStatusLabel, ByVal text As String)
        If Me.StatusStrip1.InvokeRequired Then
            Me.StatusStrip1.Invoke(New Action(Of ToolStripStatusLabel, String)(AddressOf Me.setText), New Object() {control, text})
        Else
            control.Text = text
        End If
    End Sub

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        MyBase.OnLoad(e)

        Me.m_Timer = New Threading.Timer(New TimerCallback(AddressOf Me.ProcessRunningCallback), Nothing, 1000, 1000)
    End Sub

    Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs)
        MyBase.OnClosing(e)

        If Me.m_Timer IsNot Nothing Then
            Me.m_Timer.Dispose()
            Me.m_Timer = Nothing
        End If
    End Sub

    ''' <summary>
    ''' 添加用户控件
    ''' </summary>
    ''' <param name="controller"></param>
    ''' <remarks></remarks>
    Protected Overridable Sub AddController(ByVal controller As UserControl)
        controller.Dock = DockStyle.Fill
        Me.pnlContainer.Controls.Add(controller)
    End Sub

End Class